using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using DTO;
using BUS;
using Utility;

namespace BUS
{
  public  class Phieu_Deal_BUS
    {
        public static void Insert(Phieu_Deal_DTO Phieu_Deal)
        {
            Phieu_Deal_DAL  PhieuDeal_DAL = new Phieu_Deal_DAL ();
            PhieuDeal_DAL.Insert(Phieu_Deal);
        }
        public static void Update(Phieu_Deal_DTO Phieu_Deal)
        {
            Phieu_Deal_DAL PhieuDeal_DAL = new Phieu_Deal_DAL();
            PhieuDeal_DAL.Update(Phieu_Deal);
        }
        public static void Delete(string iD)
        {
            Phieu_Deal_DAL PhieuDeal_DAL = new Phieu_Deal_DAL();
            PhieuDeal_DAL.Delete (iD);
        }
        public static PhieuDealCollection  Get(string where,
            int pageindex,
            int pagesize,
            string orderby,
            string orderdirection,
            out int total)
        {
            Phieu_Deal_DAL PhieuDeal_DAL = new Phieu_Deal_DAL();
            return PhieuDeal_DAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static PhieuDealCollection  GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            Phieu_Deal_DAL PhieuDeal_DAL = new Phieu_Deal_DAL();
            return PhieuDeal_DAL.Get(cri.Criter, 0, 0, PhieuDealColumns.MaPhieu .ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static Phieu_Deal_DTO  GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, PhieuDealColumns.MaPhieu .ToString(), Condition.EQUAL, iD);
            Phieu_Deal_DAL PhieuDeal_DAL = new Phieu_Deal_DAL();
            PhieuDealCollection  phiedealCollection = PhieuDeal_DAL.Get(cri.Criter,
                0, 0, PhieuDealColumns.MaPhieu .ToString(), OrderDirection.ASC.ToString(), out total);
            if (phiedealCollection.Count > 0)
                return phiedealCollection[0];
            return null;
        }
        public static PhieuDealCollection  GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            Phieu_Deal_DAL PhieuDeal_DAL = new Phieu_Deal_DAL();
            return PhieuDeal_DAL.Get(cri.Criter, 1, number,
                PhieuDealColumns.MaPhieu  .ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static PhieuDealCollection  GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            Phieu_Deal_DAL  PhieuDealDAL = new Phieu_Deal_DAL ();
            return PhieuDealDAL.Get(cri.Criter, 1, number,
                PhieuDealColumns.MaPhieu .ToString(), OrderDirection.DESC.ToString(), out total);
        }

    }
}
